package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.Response;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.entity.vo.TeacherQuery;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author zhaolie
 * @Date 2020/12/19 12:09 下午
 * @Version 1.0
 * @Description
 */

@RestController
@RequestMapping("/eduservice/teacherfront")
@Api(description = "前台讲师")
public class TeacherFrontController {

    @Resource
    private EduTeacherService teacherService;

    @Resource
    private EduCourseService courseService;

    @PostMapping("/{current}/{limit}")
    @ApiOperation("分页查询讲师")
    private Response getTeacherList(@PathVariable("current") Long current, @PathVariable("limit") Long limit) {
        Map<String, Object> teacherObject = teacherService.getTeacherList(current, limit);
        return Response.SUCCESS().data(teacherObject);
    }

    @GetMapping("/{id}")
    @ApiOperation("讲师详情")
    private Response getTeacherInfo(@PathVariable("id") Long id) {
        //1 根据讲师id查询讲师基本信息
        EduTeacher teacher = teacherService.getTeacherInfo(id);
        //2 根据讲师id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", id);
        List<EduCourse> courseList = courseService.list(wrapper);
        return Response.SUCCESS().data("rows", teacher).data("courses", courseList);
    }


}
